package com.example.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import java.util.Date;

public class ReceiveDataActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive_data);
        TextView textView = findViewById(R.id.tv_receive);
        // 从intent中获取bundle
        Bundle bundle = getIntent().getExtras();
        textView.setText(bundle.getString("sender") + ": \n" + bundle.getString("data"));


        // 向上一级页面返回结果
        findViewById(R.id.bt_finish).setOnClickListener(v -> {
            Intent intent = new Intent();
            Bundle bundle1 = new Bundle();
            bundle1.putString("sender", ReceiveDataActivity.this.getLocalClassName());
            bundle1.putString("data", new Date().toLocaleString());
            intent.putExtras(bundle1);
            // 设置返回结果
            setResult(Activity.RESULT_OK, intent);
            finish();
        });
    }
}
